home *** CD-ROM | disk | FTP | other *** search
/ Transactor / Transactor_17_1987_Transactor_Publishing.d64 / mouse code.pal (.txt) < prev    next >
Commodore BASIC  |  2023-02-26  |  3KB  |  101 lines

  1. 100 ;define variable labels
  2. 110 xpos    .byt 0      ;save x position
  3. 120 ypos    .byt 0      ;save y position
  4. 130 btns    .byt 0      ;save btn status
  5. 140 ;
  6. 150 ;subroutine to read control port 2
  7. 160 rdport  sei         ;lock out keyboard
  8. 170 lda #$c0    ;
  9. 180 sta $dc02   ;set ddr to read
  10. 190 lda #$80    ;
  11. 200 sta $dc00   ;read control port 2
  12. 210 ldx #$00    ;allow time for
  13. 220 inx:bne *-1 ;lines to settle
  14. 230 ldx $d419   ;read pot x
  15. 240 ldy $d41a   ;read pot y
  16. 250 lda #$ff    ;
  17. 260 sta $dc00   ;reset port 2
  18. 270 rts         ;
  19. 280 ;
  20. 290 ;subroutine for moving average al(NULL)rithm
  21. 300 avrg    bcs avrgp   ;if sign positive
  22. 310 avrgn   eor #-1     ;if negative, do
  23. 320 adc #1      ;reverse subt
  24. 330 lsr         ;allow half-weight
  25. 340 eor #-1     ;invert byte
  26. 350 clc         ;to preserve sign
  27. 360 adc #1      ;
  28. 370 clc:rts     ;
  29. 380 avrgp   lsr         ;allow half-weight
  30. 390 clc:rts     ;to the byte
  31. 400 ;
  32. 410 ;main routine to read the stick
  33. 420 stick   jsr rdport  ;
  34. 430 lda $dc00   ;read port 2
  35. 440 and #$0c    ;filter btn 1 & 2
  36. 450 eor #$ff    ;invert logic
  37. 460 sta btns    ;save btn1 & btn2
  38. 470 txa:sec     ;store x in xpos
  39. 480 sbc xpos    ;using a simple
  40. 490 jsr avrg    ;moving average
  41. 500 adc xpos    ;al(NULL)rithm
  42. 510 sta xpos    ;update xpos
  43. 520 tya:sec     ;store y in ypos
  44. 530 sbc ypos    ;using the same
  45. 540 jsr avrg    ;al(NULL)rithm
  46. 550 adc ypos    ;and update ypos
  47. 560 sta ypos    ;
  48. 570 ;
  49. 580 ;now test the buttons and exit
  50. 590 test    ldx #$ff    ;
  51. 600 stx $dc02   ;reset ddr
  52. 610 cli         ;finished with port
  53. 620 lda #4      ;test bit 2
  54. 630 bit btns    ;of btns
  55. 640 bne btn1    ;if btn1 pressed
  56. 650 asl         ;test bit 3
  57. 660 bit btns    ;of btns
  58. 670 bne btn2    ;if btn2 pressed
  59. 680 rts         ;exit z=1 no btns
  60. 690 btn1    lda #-1     ;flag for btn1
  61. 700 .byt $2c     ;skip over
  62. 710 btn2    lda #1      ;flag for btn2
  63. 720 rts         ;exit z=0
  64. 730 ;
  65. 740 ;main routine to read the mouse
  66. 750 mouse   jsr rdport  ;
  67. 760 lda $dc00   ;read port 2
  68. 770 and #$10    ;filter btn1
  69. 780 sta btns    ;save bit 4
  70. 790 txa         ;read pot x
  71. 800 bmi low     ;discern state
  72. 810 high    lda #$20    ;set bit 5
  73. 820 .byt $2c     ;skip over
  74. 830 low     lda #$00    ;clr bit 5
  75. 840 ora btns    ;combine bits 4 & 5
  76. 850 lsr:lsr     ;shift to bits 2 & 3
  77. 860 eor #$ff    ;invert logic
  78. 870 sta btns    ;save btn1 & btn2
  79. 880 ;now we have our left and right buttons!
  80. 890 lda $dc00   ;read port 2
  81. 900 and #$0f    ;filter directions
  82. 910 cmp #$0f    ;"any movement ?
  83. 920 beq exit    ;no, finish up
  84. 930 tax         ;yes, mouse rolling
  85. 940 up      [175] #1      ;check up
  86. 950 bne dn      ;
  87. 960 inc y[185]    ;
  88. 970 dn      txa         ;
  89. 980 [175] #2      ;check down
  90. 990 bne lft     ;
  91. 1000 dec y[185]    ;
  92. 1010 lft     txa         ;
  93. 1020 [175] #4      ;check left
  94. 1030 bne rht     ;
  95. 1040 dec x[185]    ;
  96. 1050 rht     txa         ;
  97. 1060 [175] #8      ;check right
  98. 1070 bne exit    ;
  99. 1080 inc x[185]    ;
  100. 1090 exit    jmp test    ;test but[164]n [175] exit
  101.